/**
 * Created by hama on 2016/6/11.
 */

var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');


//加入模板
var template = require('art-template');

var app = express();



app.use(express.static('www'));
app.use(bodyParser.urlencoded({extended:true}));
app.use(cookieParser());

//设置模板
app.engine('html', template.__express)
app.set('view engine', 'html')

/*--------------------公用--------------------*/

template.helper('ms', function(t){
    t = new Date(t)
    return t.getTime()
})

template.helper('formatTime', function(t){
    t = new Date(t)

    var M = t.getMonth() + 1,
        d = t.getDate(),
        h = t.getHours(),
        m = t.getMinutes()

    M = M < 10 ? '0' + M : M
    d = d < 10 ? '0' + d : d
    h = h < 10 ? '0' + h : h
    m = m < 10 ? '0' + m : m

    return t.getFullYear() + '-' + M + '-' + d + ' ' + h + ':' + m
})









// 现在cookie里面只有当前登录的用户名












//记得把JS文件中的地址也改了

//使用路由
app.use(require('./routes/answer'));
app.use(require('./routes/ask'));
app.use(require('./routes/index'));
app.use(require('./routes/user'));
app.use(require('./routes/register'));
app.use(require('./routes/signin'));





app.listen(3000,function(){
    console.log('node is OK');
})


